unit PesquisaEmpresa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFormPesquisa, DB, DBTables, StdCtrls, Grids, DBGrids, Buttons,
  ExtCtrls, Mask;

type
  TFPesquisaEmpresa = class(TFormPesquisa)
    Label9: TLabel;
    MECpfCNPJ: TMaskEdit;
    Label1: TLabel;
    Label2: TLabel;
    ENome: TEdit;
    EFantasia: TEdit;
    procedure BtnConsultarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BtnImprimirClick(Sender: TObject);
    procedure BtnSelecionarClick(Sender: TObject);
    procedure BtnLimparClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FPesquisaEmpresa: TFPesquisaEmpresa;

implementation

uses CadastroEmpresa, RelatorioEmpresa, UFormRelatorio;


{$R *.dfm}

procedure TFPesquisaEmpresa.BtnConsultarClick(Sender: TObject);
begin
 QPesquisa.close;
 QPesquisa.SQL.Clear;
 QPesquisa.SQL.Add('Select Emp_Codigo as Codigo,Emp_Razao as Razao,Emp_Fantasia as Fantasia,Emp_Fone as Fone,Emp_Fax as Fone2,Emp_Responsavel as Responsavel from Empresa ');
 QPesquisa.SQL.Add('Where (Emp_Codigo = Emp_Codigo)');
 if ENome.Text <> '' then
  begin
   QPesquisa.SQL.Add(' And (Emp_Razao Like :Raz)');
   QPesquisa.ParamByName('Raz').AsString:='%' + ENome.Text +'%' ;
  end;

 if EFantasia.Text <> '' then
  begin
   QPesquisa.SQL.Add(' And (Emp_Fantasia Like :Fant)');
   QPesquisa.ParamByName('Fant').AsString:='%' + EFantasia.Text +'%' ;
  end;

 QPesquisa.Open;
  inherited;
end;

procedure TFPesquisaEmpresa.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 FCadastroEmpresa.Enabled:=true;
 FCadastroEmpresa.Show;
 FPesquisaEmpresa:=nil;
 inherited;
end;

procedure TFPesquisaEmpresa.BtnImprimirClick(Sender: TObject);
begin
  inherited;
 DSPesquisa.Enabled:=false;
 Application.CreateForm(TFRelatorioEmpresa, FRelatorioEmpresa);
 with FRelatorioEmpresa do
  begin
   QRLNomeRelatorio.Caption:='EMPRESAS';
   QuickRep1.DataSet:=QPesquisa;
   QuickRep1.Prepare;
   QuickRep1.Preview;
   close;
  end;
 DSPesquisa.Enabled:=true;
end;

procedure TFPesquisaEmpresa.BtnSelecionarClick(Sender: TObject);
begin
  inherited;
  {
 FCadastroEmpresa.QEmpresa.Close;
 FCadastroEmpresa.QEmpresa.Open;
 FCadastroEmpresa.QEmpresa.Locate('Emp_Codigo',QPesquisa.fieldByname('Codigo').AsString,[loCaseInsensitive]);
 Self.Close;
  }
end;

procedure TFPesquisaEmpresa.BtnLimparClick(Sender: TObject);
begin
  inherited;
 ENome.Text:='';
 EFantasia.Text:='';
 MECpfCNPJ.Text:='';
end;

end.
